import React, { useState } from 'react'

// !问题：每次点击按钮都会开启一个新的定时器来控制 count，导致数据乱了
export default function Test() {
  const [count, setCount] = useState(10)

  const handleClick = () => {
    setInterval(() => {
      setCount((count) => count - 1)
    }, 1000)
  }
  return (
    <div>
      <h3>{count}</h3>
      <button onClick={handleClick}>倒计时</button>
    </div>
  )
}
